package cn.appsys.controller.devuser;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.appsys.pojo.DevUser;
import cn.appsys.service.devuser.DevUserService;
import cn.appsys.tools.Constants;

/**
 * 开发者登录控制器
 * 
 * @author chenglong
 *
 */
@Controller
public class devLoginController {

	@Resource
	DevUserService devUserService;

	/**
	 * @author chenglong
	 * 进入登陆界面
	 */
	@RequestMapping(value = "/devUserLogin.html")
	public String devUserLogin() {
		return "dev/devLogin";
	}
	/**
	 * @author chenglong
	 * 验证登陆
	 * @return
	 */
	@RequestMapping(value = "/devLogin")
	public String devLogin(@RequestParam("devName") String devCode, @RequestParam("devPassword") String devPassword,
			HttpServletRequest request, HttpSession session) {
		DevUser devUser = devUserService.devLogin(devCode);
		if (devUser == null) {
			// 用户不存在
			request.setAttribute("error", "用户不存在");
			return "dev/devLogin";
		} else {
			// 登陆成功
			if (!devUser.getDevPassword().equals(devPassword)) {
				// 密码错误
				request.setAttribute("error", "密码错误");
				return "dev/devLogin";
			} else {
				session.setAttribute(Constants.DEV_USER_SESSION, devUser);
				return "dev/main";		//登陆成功
			}	
		}
	}

}
